In this example, a rulebase listener is used to install a decision report filter that can hide attributes from a decision report based on the value of another attribute. Given attribute with a name of (for example) 'foo', it looks for an attribute whose name is 'foo_show' and if foo_show has a value of false, then the attribute foo and its proof is hidden from the decision report.
This file should be created in the include folder of the rulebase project, with the following contents:
<listeners>
<listener>
<handler platform="dotnet" class="DecisionFilteringExample.ExampleRulebaseListener"/>
<handler platform="java" class="com.oracle.determinations.example.ExampleRulebaseListener"/>
</listener>
</listeners>
The following code should be compiled into a JAR file and copied into the include\lib folder of the rulebase project.
public class ExampleRulebaseListener implements RulebaseListener {
ExampleDecisionReportFilter m_DecisionReportFilter;
public void initialize(Rulebase rb, Map properties, FilesContainer files) {
m_DecisionReportFilter = new ExampleDecisionReportFilter();
}
public void sessionCreated(Session session) {
session.setDecisionReportFilter(m_DecisionReportFilter);
}
}
public class ExampleDecisionReportFilter implements DecisionReportFilter {
public DecisionReportFilterResult getAttributeFilter(EntityInstance instance, Attribute attr) {
Attribute filterAttr = instance.getEntity().getAttribute(attr.getName() + "_show");
if (filterAttr != null && Boolean.FALSE.equals(filterAttr.getValue(instance))) {
return DecisionReportFilterResult.SILENT_INVISIBLE;
}
return DecisionReportFilterResult.UNFILTERED;
}
public DecisionReportFilterResult getRelationshipFilter(EntityInstance instance, Relationship attr) {
return DecisionReportFilterResult.UNFILTERED;
}
}
The following code should be compiled into an assembly DLL and copied into the include\lib folder of the rulebase project.
public class ExampleRulebaseListener : RulebaseListener
{
ExampleDecisionReportFilter m_DecisionFilter;
public void Initialize(Rulebase rb, Oracle.Determinations.Masquerade.Util.Map properties, FilesContainer files)
{
m_DecisionFilter = new ExampleDecisionReportFilter();
}
public void SessionCreated(Session session)
{
session.SetDecisionReportFilter(m_DecisionFilter);
}
}
class ExampleDecisionReportFilter : DecisionReportFilter
{
public DecisionReportFilterResult GetAttributeFilter(EntityInstance instance, RBAttr attr)
{
RBAttr filterAttr = instance.GetEntity().GetAttribute(attr.GetName() + "_show");
if (filterAttr != null && Oracle.Determinations.Masquerade.Lang.Boolean.FALSE.Equals(filterAttr.GetValue(instance)))
{
return DecisionReportFilterResult.SILENT_INVISIBLE;
}
return DecisionReportFilterResult.UNFILTERED;
}
public DecisionReportFilterResult GetRelationshipFilter(EntityInstance instance, Relationship attr)
{
return DecisionReportFilterResult.UNFILTERED;
}
}